// 搜索接口
import 'dart:convert';

import 'package:xiecheng_lvyou/model/search_model.dart';
import 'package:http/http.dart' as http;

class SearchDao {

  

  static Future <SearchModel> fetch(String url,String keyword) async {
    Map<String, dynamic> param = {'source':'mobileweb','action':'mobileweb','keyword':keyword};
    // param.set
    var url = Uri.https('m.ctrip.com','restapi/h5api/globalsearch/search',param);
    final response = await http.get(url);
    if (response.statusCode == 200) {
      Utf8Decoder utf8decoder = const Utf8Decoder(); // fix 中文乱码
      var result = json.decode(utf8decoder.convert(response.bodyBytes));
      SearchModel model = SearchModel.fromJson(result);
      model.keyword = keyword;
      return model;
    }else {
      throw Exception('Failed to load search_page.json');
    }
  }
}